let user = localStorage.user && JSON.parse(localStorage.user)
let body = document.querySelector('.body')
let dropdown = document.querySelector('.dropdown-lift')
let dropdowns = document.querySelector('.dropdown-right')
let title = document.querySelector('.tit')
let main = document.querySelector('.main')



//发送请求，获取用户数据
renderContents()
async function renderContents(){
    let res = await axios({
        method:'get',
        url:'/api/user',
        params:{
            userId:user.userId
            // userId: "632595e0e24deb53641c4b2b"
        }
    })
    //渲染数据
    console.log(res.data.data);
    let data = res.data.data

    renderUserList2(data) 
    function renderUserList2(data) {
    let reminds = '';
        reminds +=`
        <a href="" class="title">${data.username}</a>
        <span class="caret"></span>
        <ul class="userdisplay">
            <li>
                <a href="../lk/my-diary.html">我的日记</a>
            </li>
            <li>
                <a href="guanzhudereng.html">我关注的人</a>
            </li>
            <li>
                <a href="">设置</a>
            </li>
            <li>
                <a href="../dc/login.html">退出</a>
            </li>
        </ul>
        `
    dropdowns.innerHTML = reminds
}

            let remind = '';
                remind +=`
                    <a href="tixing.html" class="title">提醒(${0})</a>
                    <span class="caret"></span>
                    <ul class="msg">
                        <li>没有提醒</li>
                    </ul>
                `
            dropdown.innerHTML = remind
     //  发送请求，获取关注用户的数量
     renderContents3()
     async function renderContents3(){
         let res3 = await axios({
             method:'get',
             url:'/api/user',
             params:{
                userId:user.userId
            // userId: "632595e0e24deb53641c4b2b"
             }
         })
         //渲染数据
         let data = res3.data.data
         console.log( 111,res3.data.data);
         let id = data.idolId.length
         let ids = data.fansId.length
         if(data == null ){
             let html = '';
             html += `<a href="guanzhudereng.html">我关注的人(${0})</a>
                     <a href="guanzhugeren1.html">关注我的人(${0})</a>
                     `
                     title.innerHTML = html
             }else{
                     let html = '';
                     html += `
                     <a href="guanzhudereng.html">我关注的人(${id})</a>
                     <a href="guanzhugeren1.html">关注我的人(${ids})</a>
                             `
                     title.innerHTML = html
             }
     }

    //发送请求，获取关注用户
        renderContents4()
        async function renderContents4(){
            let res4 = await axios({
                method:'get',
                url:'/api/user',
                params:{
                    userId:user.userId
            // userId: "632595e0e24deb53641c4b2b"
                }
            })
        //渲染数据
        let data = res4.data.data.fansId
        console.log(1111,data);
        if(data == null ){
                return
            }else{
                let html = '';
                for (const item of data) {
                    console.log(item);
                    let res = await axios({
                        method:'get',
                        url:'/api/user',
                        params:{
                            userId:`${item}`
                        }
                    })
                    let ccc = res.data.data
                    console.log(333,ccc);
                    html += `
                        <div class="people">
                            <a href="">
                                <img src="http://localhost:8000${ccc.headphoto}" alt="">
                            </a>
                            <span>
                                <a href="">${ccc.username}</a>
                                <span class="guanzhu">
                                    <button>取消被关注</button>
                                </span>
                            </span>
                        </div>
                        `
            }
            body.innerHTML = html
    }
}}